home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / mpm_common.h.z / mpm_common.h
C/C++ Source or Header  |  2002-07-08  |  10KB  |  293 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. /* The purpose of this file is to store the code that MOST mpm's will need
  60.  * this does not mean a function only goes into this file if every MPM needs
  61.  * it.  It means that if a function is needed by more than one MPM, and
  62.  * future maintenance would be served by making the code common, then the
  63.  * function belongs here.
  64.  *
  65.  * This is going in src/main because it is not platform specific, it is
  66.  * specific to multi-process servers, but NOT to Unix.  Which is why it
  67.  * does not belong in src/os/unix
  68.  */
  69.  
  70. #ifndef APACHE_MPM_COMMON_H
  71. #define APACHE_MPM_COMMON_H
  72.  
  73. #include "ap_config.h"
  74.  
  75. #if APR_HAVE_NETINET_TCP_H
  76. #include <netinet/tcp.h>    /* for TCP_NODELAY */
  77. #endif
  78.  
  79. #include "mpm.h"
  80.  
  81. #ifdef __cplusplus
  82. extern "C" {
  83. #endif
  84.  
  85. /**
  86.  * @package Multi-Processing Modules functions
  87.  */
  88.  
  89. /* The maximum length of the queue of pending connections, as defined
  90.  * by listen(2).  Under some systems, it should be increased if you
  91.  * are experiencing a heavy TCP SYN flood attack.
  92.  *
  93.  * It defaults to 511 instead of 512 because some systems store it 
  94.  * as an 8-bit datatype; 512 truncated to 8-bits is 0, while 511 is 
  95.  * 255 when truncated.
  96.  */
  97. #ifndef DEFAULT_LISTENBACKLOG
  98. #define DEFAULT_LISTENBACKLOG 511
  99. #endif
  100.         
  101. /**
  102.  * Make sure all child processes that have been spawned by the parent process
  103.  * have died.  This includes process registered as "other_children".
  104.  * @warning This is only defined if the MPM defines 
  105.  *          MPM_NEEDS_RECLAIM_CHILD_PROCESS
  106.  * @param terminate Either 1 or 0.  If 1, send the child processes SIGTERM
  107.  *        each time through the loop.  If 0, give the process time to die
  108.  *        on its own before signalling it.
  109.  * @tip This function requires that some macros are defined by the MPM: <pre>
  110.  *  MPM_CHILD_PID -- Get the pid from the specified spot in the scoreboard
  111.  *  MPM_NOTE_CHILD_KILLED -- Note the child died in the scoreboard
  112.  * </pre>
  113.  */
  114. #ifdef AP_MPM_WANT_RECLAIM_CHILD_PROCESSES
  115. void ap_reclaim_child_processes(int terminate);
  116. #endif
  117.  
  118. /**
  119.  * Determine if any child process has died.  If no child process died, then
  120.  * this process sleeps for the amount of time specified by the MPM defined
  121.  * macro SCOREBOARD_MAINTENANCE_INTERVAL.
  122.  * @param status The return code if a process has died
  123.  * @param ret The process id of the process that died
  124.  * @param p The pool to allocate out of
  125.  */
  126. #ifdef AP_MPM_WANT_WAIT_OR_TIMEOUT
  127. void ap_wait_or_timeout(apr_exit_why_e *status, int *exitcode, apr_proc_t *ret, 
  128.                         apr_pool_t *p);
  129. #endif
  130.  
  131. /**
  132.  * Log why a child died to the error log, if the child died without the
  133.  * parent signalling it.
  134.  * @param pid The child that has died
  135.  * @param status The status returned from ap_wait_or_timeout
  136.  * @return 0 on success, APEXIT_CHILDFATAL if MPM should terminate
  137.  */
  138. #ifdef AP_MPM_WANT_PROCESS_CHILD_STATUS
  139. int ap_process_child_status(apr_proc_t *pid, apr_exit_why_e why, int status);
  140. #endif
  141.  
  142. #if defined(TCP_NODELAY) && !defined(MPE) && !defined(TPF)
  143. /**
  144.  * Turn off the nagle algorithm for the specified socket.  The nagle algorithm
  145.  * says that we should delay sending partial packets in the hopes of getting
  146.  * more data.  There are bad interactions between persistent connections and
  147.  * Nagle's algorithm that have severe performance penalties.
  148.  * @param s The socket to disable nagle for.
  149.  */
  150. void ap_sock_disable_nagle(apr_socket_t *s);
  151. #else
  152. #define ap_sock_disable_nagle(s)        /* NOOP */
  153. #endif
  154.  
  155. #ifdef HAVE_GETPWNAM
  156. /**
  157.  * Convert a username to a numeric ID
  158.  * @param name The name to convert
  159.  * @return The user id corresponding to a name
  160.  * @deffunc uid_t ap_uname2id(const char *name)
  161.  */
  162. AP_DECLARE(uid_t) ap_uname2id(const char *name);
  163. #endif
  164.  
  165. #ifdef HAVE_GETGRNAM
  166. /**
  167.  * Convert a group name to a numeric ID
  168.  * @param name The name to convert
  169.  * @return The group id corresponding to a name
  170.  * @deffunc gid_t ap_gname2id(const char *name)
  171.  */
  172. AP_DECLARE(gid_t) ap_gname2id(const char *name);
  173. #endif
  174.  
  175. #define AP_MPM_HARD_LIMITS_FILE APACHE_MPM_DIR "/mpm_default.h"
  176.  
  177. #ifdef AP_MPM_USES_POD
  178.  
  179. typedef struct ap_pod_t ap_pod_t;
  180.  
  181. struct ap_pod_t {
  182.     apr_file_t *pod_in;
  183.     apr_file_t *pod_out;
  184.     apr_pool_t *p;
  185.     apr_sockaddr_t *sa;
  186. };
  187.  
  188. /**
  189.  * Open the pipe-of-death.  The pipe of death is used to tell all child
  190.  * processes that it is time to die gracefully.
  191.  * @param p The pool to use for allocating the pipe
  192.  */
  193. AP_DECLARE(apr_status_t) ap_mpm_pod_open(apr_pool_t *p, ap_pod_t **pod);
  194.  
  195. /**
  196.  * Check the pipe to determine if the process has been signalled to die.
  197.  */
  198. AP_DECLARE(apr_status_t) ap_mpm_pod_check(ap_pod_t *pod);
  199.  
  200. /**
  201.  * Close the pipe-of-death
  202.  */
  203. AP_DECLARE(apr_status_t) ap_mpm_pod_close(ap_pod_t *pod);
  204.  
  205. /**
  206.  * Write data to the pipe-of-death, signalling that one child process
  207.  * should die.
  208.  * @param p The pool to use when allocating any required structures.
  209.  */
  210. AP_DECLARE(apr_status_t) ap_mpm_pod_signal(ap_pod_t *pod);
  211.  
  212. /**
  213.  * Write data to the pipe-of-death, signalling that all child process
  214.  * should die.
  215.  * @param p The pool to use when allocating any required structures.
  216.  * @param num The number of child processes to kill
  217.  */
  218. AP_DECLARE(void) ap_mpm_pod_killpg(ap_pod_t *pod, int num);
  219. #endif
  220.  
  221. /*
  222.  * These data members are common to all mpms. Each new mpm
  223.  * should either use the appropriate ap_mpm_set_* function
  224.  * in their command table or create their own for custom or
  225.  * OS specific needs. These should work for most.
  226.  */
  227.  
  228. /**
  229.  * The maximum number of requests each child thread or
  230.  * process handles before dying off
  231.  */
  232. #ifdef AP_MPM_WANT_SET_MAX_REQUESTS
  233. extern int ap_max_requests_per_child;
  234. const char *ap_mpm_set_max_requests(cmd_parms *cmd, void *dummy,
  235.                                     const char *arg);
  236. #endif
  237.  
  238. /**
  239.  * The filename used to store the process id.
  240.  */
  241. #ifdef AP_MPM_WANT_SET_PIDFILE
  242. extern const char *ap_pid_fname;
  243. const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy,
  244.                                const char *arg);
  245. #endif
  246.  
  247. /**
  248.  * The name of lockfile used when Apache needs to lock the accept() call.
  249.  */
  250. #ifdef AP_MPM_WANT_SET_LOCKFILE
  251. extern const char *ap_lock_fname;
  252. const char *ap_mpm_set_lockfile(cmd_parms *cmd, void *dummy,
  253.                                 const char *arg);
  254. #endif
  255.  
  256. /**
  257.  * The system mutex implementation to use for the accept mutex.
  258.  */
  259. #ifdef AP_MPM_WANT_SET_ACCEPT_LOCK_MECH
  260. extern apr_lockmech_e ap_accept_lock_mech;
  261. extern const char ap_valid_accept_mutex_string[];
  262. const char *ap_mpm_set_accept_lock_mech(cmd_parms *cmd, void *dummy,
  263.                                         const char *arg);
  264. #endif
  265.  
  266. /*
  267.  * Set the scorboard file.
  268.  */
  269. #ifdef AP_MPM_WANT_SET_SCOREBOARD
  270. const char *ap_mpm_set_scoreboard(cmd_parms *cmd, void *dummy,
  271.                                   const char *arg);
  272. #endif
  273.  
  274. /*
  275.  * The directory that the server changes directory to dump core.
  276.  */
  277. #ifdef AP_MPM_WANT_SET_COREDUMPDIR
  278. extern char ap_coredump_dir[MAX_STRING_LEN];
  279. const char *ap_mpm_set_coredumpdir(cmd_parms *cmd, void *dummy,
  280.                                    const char *arg);
  281. #endif
  282.  
  283. #ifdef AP_MPM_WANT_SIGNAL_SERVER
  284. int ap_signal_server(int *, apr_pool_t *);
  285. void ap_mpm_rewrite_args(process_rec *);
  286. #endif
  287.  
  288. #ifdef __cplusplus
  289. }
  290. #endif
  291.  
  292. #endif /* !APACHE_MPM_COMMON_H */
  293.